<template>
	<uni-section title="" type="line">
		<uni-list>
			<uni-list-item v-for="item in listData" :title="item.taskName"
				:rightText="item.alarmDatetime" link="navigateTo"
				:to="'/pages/early-warning-detail/index?id=' + item.id" showArrow />
		</uni-list>
	</uni-section>
	<div class="space"></div>
	<uni-pagination title="标题文字" prev-text="前一页" next-text="后一页" :total="total" :current="current"
		@change="handlePage" />
</template>

<script setup>
import {
	ref
} from "vue";
import {
	onShow
} from '@dcloudio/uni-app';
import {
	HOST
} from "../../static/js/const";

let listData = ref([]);
let total = ref(0);
let current = ref(1);
let pageSize = ref(5);

const handlePage = (params) => {
	current.value = params.current;
	onQuery()
}

const warningStatus = value => {
	const v = Number(value);
	if (v === 0) {
		return "待处理";
	} else if (v === 1) {
		return "已处理";
	}
}

const onQuery = () => {
	uni.request({
		url: `${HOST}/alarm/alarmInfo/pageSearch`, // ${HOST}/dir/from/leftBehindChildren/pageSearch
		method: 'POST',
		header: {
			'content-type': 'application/json',
			'Authorization': 'Bearer ' + uni.getStorageSync('accessToken')
		},
		data: {
			current: current.value,
			size: pageSize.value,
			data: {
				alarmType: "1",
				warningStatus: "0"
			}
		},
		success: (res) => {
			if (res.data.status === "OK" && res.data.flag) {
				listData.value = res.data.data.records;
				total.value = res.data.data.total;
			} else if (Number(res.data.code) === 401) {
				uni.showToast({
					title: "登录超时",
					icon: "error"
				});
				uni.removeStorageSync('accessToken');
				uni.reLaunch({
					url: '/pages/login/index' // 这里的URL是登录页面的路径
				});
			} else {
				uni.showToast({
					title: res.data.message,
					icon: "error"
				});
			}
		},
		fail: (err) => {
			console.error('请求失败', err);
			uni.showToast({
				title: "连接失败",
				icon: "error"
			});
		}
	});
}

onShow(() => {
	onQuery();
})
</script>

<style lang="scss" scoped></style>